import { cloneDeep, } from 'lodash-es';

let postList: PostRecord[] = [
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 1, postCode: "ceo", postName: "董事长", postSort: 1, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 2, postCode: "se", postName: "项目经理", postSort: 2, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 3, postCode: "hr", postName: "人力资源", postSort: 3, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 4, postCode: "user", postName: "普通员工", postSort: 4, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 5, postCode: "ceo", postName: "董事长", postSort: 1, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 6, postCode: "se", postName: "项目经理", postSort: 2, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 7, postCode: "hr", postName: "人力资源", postSort: 3, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 8, postCode: "user", postName: "普通员工", postSort: 4, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 9, postCode: "ceo", postName: "董事长", postSort: 1, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 10, postCode: "se", postName: "项目经理", postSort: 2, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 11, postCode: "ceo", postName: "董事长", postSort: 1, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 12, postCode: "se", postName: "项目经理", postSort: 2, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 13, postCode: "hr", postName: "人力资源", postSort: 3, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 14, postCode: "user", postName: "普通员工", postSort: 4, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 15, postCode: "ceo", postName: "董事长", postSort: 1, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 16, postCode: "se", postName: "项目经理", postSort: 2, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 17, postCode: "hr", postName: "人力资源", postSort: 3, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 18, postCode: "user", postName: "普通员工", postSort: 4, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 19, postCode: "ceo", postName: "董事长", postSort: 1, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 20, postCode: "se", postName: "项目经理", postSort: 2, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 21, postCode: "ceo", postName: "董事长", postSort: 1, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 22, postCode: "se", postName: "项目经理", postSort: 2, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 23, postCode: "hr", postName: "人力资源", postSort: 3, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 24, postCode: "user", postName: "普通员工", postSort: 4, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 25, postCode: "ceo", postName: "董事长", postSort: 1, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 26, postCode: "se", postName: "项目经理", postSort: 2, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 27, postCode: "hr", postName: "人力资源", postSort: 3, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 28, postCode: "user", postName: "普通员工", postSort: 4, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 29, postCode: "ceo", postName: "董事长", postSort: 1, status: "0", flag: false },
  { createBy: "admin", createTime: "2024-07-07 17:41:52", updateBy: null, updateTime: null, remark: "", postId: 30, postCode: "se", postName: "项目经理", postSort: 2, status: "0", flag: false },
];

const mocks: MockRecord[] = [
  {
    method: "get",
    url: "/api/system/post/list",
    response(option) {
      const copyList = cloneDeep(postList);

      let resList = postList;

      if (option.query.pageNum) {
        resList = copyList.splice((option.query.pageNum - 1) * option.query.pageSize, option.query.pageSize);
      }

      const resData: responseType = {
        code: 200,
        msg: "查询成功",
        total: postList.length,
        ...(option.query.pageNum ? { rows: resList } : { data: resList })
      }

      return resData;
    }
  },
  {
    method: "get",
    url: "/api/system/post/:postId",
    response(option) {
      const resPost = postList.find(item => item.postId == option.query.postId);

      const resData: responseType = {
        code: resPost ? 200 : 500,
        msg: resPost ? "查询成功" : "查询失败",
        data: resPost,
      }

      return resData;
    }
  },
  {
    method: "post",
    url: "/api/system/post",
    response(option) {
      const newPost = option.body;

      newPost.postId = postList.length + 1;
      postList.unshift(newPost);

      const resData: responseType = {
        code: 200,
        msg: "新增成功",
      }

      return resData;
    }
  },
  {
    method: "put",
    url: "/api/system/post",
    response(option) {
      const newPost = option.body;

      const index = postList.findIndex(item => item.postId == newPost.postId);

      postList.splice(index, 1, newPost);

      const resData: responseType = {
        code: 200,
        msg: "修改成功",
      }

      return resData;
    }
  },
  {
    method: "delete",
    url: "/api/system/post/:postIds",
    response(option) {
      const postIds = option.query.postIds.split(',');

      const filterList = postList.filter(item => !postIds.includes(String(item.postId)));

      postList = filterList;

      const resData: responseType = {
        code: 200,
        msg: "删除成功",
      }
      return resData;
    }
  }
];

export default mocks;